package com.hot100.mid;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 前缀树
 * @date 2022/9/12 15:56
 */
public class Demo39 {

    class Trie {
        List<String>  tri;
        public Trie() {
            tri=new ArrayList<>();
        }

        public void insert(String word) {
            tri.add(word);
        }

        public boolean search(String word) {
            return tri.contains(word);
        }

        public boolean startsWith(String prefix) {
            for (String s : tri) {
                if (s.startsWith(prefix)) {
                    return true;
                }
            }
            return false;
        }
    }
}
